package net.aaa.hotel.controller;

import net.aaa.hotel.dao.HRoleDao;
import net.aaa.hotel.dao.impl.HRoleDaoImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("ro")
public class RoleSpringController {
    @Autowired
    HRoleDao dao = new HRoleDaoImpl();

    @RequestMapping("quanFen")
    public List<Map> quanFen(){
        List<Map> maps = dao.quanFen();
        return maps;
    }
    @RequestMapping("queryQuan")
    public List<Map> queryQuan(Integer rid){
        List<Map> maps = dao.queryQuan(rid);
        return maps;
    }
    @RequestMapping("tianQuan")
    public int tianQuan(HttpServletRequest request){
        int rid = Integer.parseInt(request.getParameter("rid") + "");
       int i = dao.del(rid);
        String mid = request.getParameter("mid");
        String[] split = mid.split(",");
        int a=0;
        for (String s : split) {
            int p = Integer.parseInt(s);
           a+= dao.addRoleQuan(p,rid);
        }
        return a;
    }
}
